package com.xqboss.apps.controller.punch;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xqboss.apps.convert.punch.PunchUserRecordConverter;
import com.xqboss.apps.domain.punch.PunchUserRecord;
import com.xqboss.apps.dto.PageDto;
import com.xqboss.apps.service.punch.PunchUserRecordService;
import com.xqboss.apps.vo.punch.UserPunchRecordVo;
import com.xqboss.common.core.controller.BaseController;
import com.xqboss.common.core.domain.R;
import com.xqboss.common.core.page.PageDomain;
import com.xqboss.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Trent
 * @date 2023/8/15
 */
@Api(tags = "打卡-用户打卡记录")
@RestController
@RequestMapping("/punch/record")
public class PunchUserRecordController extends BaseController {

    @Autowired
    private PunchUserRecordService punchUserRecordService;

    @Autowired
    private PunchUserRecordConverter punchUserRecordConverter;

    @ApiOperation("获取用户打卡记录")
    @GetMapping("list")
    public R<List<UserPunchRecordVo>> list(PageDto pageInfo){
        pageInfo.setOrderByColumn("id");
        pageInfo.setSortAsc(false);
        pageInfo.startPageAndOrder();
        List<PunchUserRecord> list = punchUserRecordService.getUserPunchRecordList(getUserId());
        List<UserPunchRecordVo> voList = punchUserRecordConverter.toVoList(list);
        return R.ok(voList, list);
    }

}
